{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Stock Logistic Regression"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "# Library\n",
        "import pandas as pd\n",
        "import numpy as np\n",
        "import math\n",
        "\n",
        "# Plot Visualization\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns\n",
        "plt.rc(\"font\", size=14)\n",
        "sns.set(style=\"white\")\n",
        "sns.set(style=\"whitegrid\", color_codes=True)\n",
        "\n",
        "# Machine Learning Libraries\n",
        "from sklearn.linear_model import LogisticRegression\n",
        "from sklearn.model_selection import train_test_split\n",
        "from sklearn import metrics\n",
        "from sklearn.model_selection import cross_val_score\n",
        "\n",
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "import fix_yahoo_finance as yf\n",
        "yf.pdr_override()"
      ],
      "outputs": [],
      "execution_count": 1,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "stock_name = 'AMD'\n",
        "start = '2010-01-01' \n",
        "end = '2018-09-27'\n",
        "df = yf.download(stock_name, start, end)\n",
        "df = df.reset_index()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 downloaded\n"
          ]
        }
      ],
      "execution_count": 2,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 3,
          "data": {
            "text/plain": [
              "        Date  Open  High   Low  Close  Adj Close    Volume\n",
              "0 2010-01-04  9.79  9.90  9.68   9.70       9.70  18748700\n",
              "1 2010-01-05  9.71  9.90  9.68   9.71       9.71  22145700\n",
              "2 2010-01-06  9.68  9.76  9.55   9.57       9.57  18643400\n",
              "3 2010-01-07  9.51  9.55  9.18   9.47       9.47  26806800\n",
              "4 2010-01-08  9.37  9.47  9.29   9.43       9.43  13752800"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Date</th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2010-01-04</td>\n",
              "      <td>9.79</td>\n",
              "      <td>9.90</td>\n",
              "      <td>9.68</td>\n",
              "      <td>9.70</td>\n",
              "      <td>9.70</td>\n",
              "      <td>18748700</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2010-01-05</td>\n",
              "      <td>9.71</td>\n",
              "      <td>9.90</td>\n",
              "      <td>9.68</td>\n",
              "      <td>9.71</td>\n",
              "      <td>9.71</td>\n",
              "      <td>22145700</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2010-01-06</td>\n",
              "      <td>9.68</td>\n",
              "      <td>9.76</td>\n",
              "      <td>9.55</td>\n",
              "      <td>9.57</td>\n",
              "      <td>9.57</td>\n",
              "      <td>18643400</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>2010-01-07</td>\n",
              "      <td>9.51</td>\n",
              "      <td>9.55</td>\n",
              "      <td>9.18</td>\n",
              "      <td>9.47</td>\n",
              "      <td>9.47</td>\n",
              "      <td>26806800</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>2010-01-08</td>\n",
              "      <td>9.37</td>\n",
              "      <td>9.47</td>\n",
              "      <td>9.29</td>\n",
              "      <td>9.43</td>\n",
              "      <td>9.43</td>\n",
              "      <td>13752800</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 3,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.groupby('Adj Close').mean()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 4,
          "data": {
            "text/plain": [
              "                Open       High        Low      Close        Volume\n",
              "Adj Close                                                          \n",
              "1.620000    1.670000   1.700000   1.610000   1.620000  1.191650e+07\n",
              "1.660000    1.755000   1.760000   1.660000   1.660000  8.895400e+06\n",
              "1.670000    1.715000   1.730000   1.650000   1.670000  1.174185e+07\n",
              "1.700000    1.775000   1.790000   1.695000   1.700000  1.169745e+07\n",
              "1.710000    1.760000   1.785000   1.695000   1.710000  7.057650e+06\n",
              "1.720000    1.690000   1.726667   1.666667   1.720000  9.223667e+06\n",
              "1.730000    1.800000   1.840000   1.720000   1.730000  9.975200e+06\n",
              "1.740000    1.770000   1.770000   1.720000   1.740000  5.531700e+06\n",
              "1.750000    1.690000   1.830000   1.650000   1.750000  1.721740e+07\n",
              "1.760000    1.800000   1.810000   1.750000   1.760000  1.064190e+07\n",
              "1.770000    1.685000   1.770000   1.670000   1.770000  1.046035e+07\n",
              "1.780000    1.710000   1.820000   1.710000   1.780000  1.218440e+07\n",
              "1.790000    1.832500   1.867500   1.762500   1.790000  1.479110e+07\n",
              "1.800000    1.811429   1.857143   1.768571   1.800000  1.289594e+07\n",
              "1.810000    1.845000   1.885000   1.800000   1.810000  5.940650e+06\n",
              "1.820000    1.880000   1.920000   1.785000   1.820000  1.159190e+07\n",
              "1.830000    1.827500   1.875000   1.790000   1.830000  9.378800e+06\n",
              "1.840000    1.853333   1.903333   1.816667   1.840000  6.646200e+06\n",
              "1.850000    1.825000   1.920000   1.790000   1.850000  1.173585e+07\n",
              "1.860000    1.837500   1.895000   1.812500   1.860000  1.143455e+07\n",
              "1.870000    1.930000   1.950000   1.855000   1.870000  1.634030e+07\n",
              "1.880000    1.880000   1.896667   1.846667   1.880000  1.345987e+07\n",
              "1.890000    1.885000   1.920000   1.860000   1.890000  5.379950e+06\n",
              "1.900000    1.882500   1.950000   1.855000   1.900000  1.109292e+07\n",
              "1.910000    1.930000   1.955000   1.865000   1.910000  9.303750e+06\n",
              "1.920000    1.885000   1.945000   1.875000   1.920000  1.273620e+07\n",
              "1.930000    1.946667   1.990000   1.876667   1.930000  1.905627e+07\n",
              "1.940000    2.000000   2.000000   1.890000   1.940000  2.154490e+07\n",
              "1.950000    1.973333   2.013333   1.913333   1.950000  1.257690e+07\n",
              "1.960000    1.935000   2.008333   1.893333   1.960000  1.696712e+07\n",
              "...              ...        ...        ...        ...           ...\n",
              "19.770000  19.120001  19.820000  18.730000  19.770000  6.061660e+07\n",
              "19.980000  19.790001  20.080000  19.350000  19.980000  6.298320e+07\n",
              "20.020000  19.969999  20.280001  19.629999  20.020000  8.919550e+07\n",
              "20.400000  19.980000  20.420000  19.860001  20.400000  5.562900e+07\n",
              "20.900000  20.280001  20.920000  20.209999  20.900000  6.200270e+07\n",
              "22.290001  21.190001  22.320000  21.139999  22.290001  1.134441e+08\n",
              "23.980000  22.910000  24.000000  22.670000  23.980000  1.643282e+08\n",
              "24.889999  25.290001  25.670000  24.760000  24.889999  1.036073e+08\n",
              "25.049999  25.510000  26.180000  24.040001  25.049999  2.157712e+08\n",
              "25.170000  24.889999  25.240000  24.719999  25.170000  6.520640e+07\n",
              "25.200001  24.360001  25.410000  24.010000  25.200001  1.432232e+08\n",
              "25.260000  24.940001  27.299999  24.629999  25.260000  3.250584e+08\n",
              "27.379999  26.959999  28.270000  26.799999  27.379999  1.233487e+08\n",
              "27.840000  28.120001  28.580000  27.190001  27.840000  1.439429e+08\n",
              "28.059999  25.620001  28.110001  25.570000  28.059999  1.925413e+08\n",
              "28.510000  29.410000  29.940001  26.840000  28.510000  2.573490e+08\n",
              "29.889999  28.150000  29.930000  27.840000  29.889999  1.622538e+08\n",
              "30.100000  30.020000  30.590000  29.370001  30.100000  1.599025e+08\n",
              "30.480000  33.160000  34.139999  29.870001  30.480000  3.041471e+08\n",
              "31.020000  31.190001  32.419998  30.910000  31.020000  1.297929e+08\n",
              "31.180000  32.099998  32.200001  30.639999  31.180000  1.231165e+08\n",
              "31.209999  31.520000  31.830000  30.510000  31.209999  1.242870e+08\n",
              "31.930000  32.990002  33.369999  31.200001  31.930000  1.766732e+08\n",
              "32.189999  32.400002  32.599998  31.719999  32.189999  7.934730e+07\n",
              "32.209999  29.910000  32.290001  29.450001  32.209999  1.978896e+08\n",
              "32.430000  31.750000  33.230000  31.600000  32.430000  1.804106e+08\n",
              "32.570000  33.180000  33.599998  32.189999  32.570000  1.185702e+08\n",
              "32.590000  31.860001  32.630001  31.389999  32.590000  8.793440e+07\n",
              "32.610001  31.129999  32.650002  30.910000  32.610001  1.183326e+08\n",
              "32.720001  31.430000  33.090000  30.540001  32.720001  2.177628e+08\n",
              "\n[987 rows x 5 columns]"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Adj Close</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1.620000</th>\n",
              "      <td>1.670000</td>\n",
              "      <td>1.700000</td>\n",
              "      <td>1.610000</td>\n",
              "      <td>1.620000</td>\n",
              "      <td>1.191650e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.660000</th>\n",
              "      <td>1.755000</td>\n",
              "      <td>1.760000</td>\n",
              "      <td>1.660000</td>\n",
              "      <td>1.660000</td>\n",
              "      <td>8.895400e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.670000</th>\n",
              "      <td>1.715000</td>\n",
              "      <td>1.730000</td>\n",
              "      <td>1.650000</td>\n",
              "      <td>1.670000</td>\n",
              "      <td>1.174185e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.700000</th>\n",
              "      <td>1.775000</td>\n",
              "      <td>1.790000</td>\n",
              "      <td>1.695000</td>\n",
              "      <td>1.700000</td>\n",
              "      <td>1.169745e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.710000</th>\n",
              "      <td>1.760000</td>\n",
              "      <td>1.785000</td>\n",
              "      <td>1.695000</td>\n",
              "      <td>1.710000</td>\n",
              "      <td>7.057650e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.720000</th>\n",
              "      <td>1.690000</td>\n",
              "      <td>1.726667</td>\n",
              "      <td>1.666667</td>\n",
              "      <td>1.720000</td>\n",
              "      <td>9.223667e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.730000</th>\n",
              "      <td>1.800000</td>\n",
              "      <td>1.840000</td>\n",
              "      <td>1.720000</td>\n",
              "      <td>1.730000</td>\n",
              "      <td>9.975200e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.740000</th>\n",
              "      <td>1.770000</td>\n",
              "      <td>1.770000</td>\n",
              "      <td>1.720000</td>\n",
              "      <td>1.740000</td>\n",
              "      <td>5.531700e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.750000</th>\n",
              "      <td>1.690000</td>\n",
              "      <td>1.830000</td>\n",
              "      <td>1.650000</td>\n",
              "      <td>1.750000</td>\n",
              "      <td>1.721740e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.760000</th>\n",
              "      <td>1.800000</td>\n",
              "      <td>1.810000</td>\n",
              "      <td>1.750000</td>\n",
              "      <td>1.760000</td>\n",
              "      <td>1.064190e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.770000</th>\n",
              "      <td>1.685000</td>\n",
              "      <td>1.770000</td>\n",
              "      <td>1.670000</td>\n",
              "      <td>1.770000</td>\n",
              "      <td>1.046035e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.780000</th>\n",
              "      <td>1.710000</td>\n",
              "      <td>1.820000</td>\n",
              "      <td>1.710000</td>\n",
              "      <td>1.780000</td>\n",
              "      <td>1.218440e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.790000</th>\n",
              "      <td>1.832500</td>\n",
              "      <td>1.867500</td>\n",
              "      <td>1.762500</td>\n",
              "      <td>1.790000</td>\n",
              "      <td>1.479110e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.800000</th>\n",
              "      <td>1.811429</td>\n",
              "      <td>1.857143</td>\n",
              "      <td>1.768571</td>\n",
              "      <td>1.800000</td>\n",
              "      <td>1.289594e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.810000</th>\n",
              "      <td>1.845000</td>\n",
              "      <td>1.885000</td>\n",
              "      <td>1.800000</td>\n",
              "      <td>1.810000</td>\n",
              "      <td>5.940650e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.820000</th>\n",
              "      <td>1.880000</td>\n",
              "      <td>1.920000</td>\n",
              "      <td>1.785000</td>\n",
              "      <td>1.820000</td>\n",
              "      <td>1.159190e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.830000</th>\n",
              "      <td>1.827500</td>\n",
              "      <td>1.875000</td>\n",
              "      <td>1.790000</td>\n",
              "      <td>1.830000</td>\n",
              "      <td>9.378800e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.840000</th>\n",
              "      <td>1.853333</td>\n",
              "      <td>1.903333</td>\n",
              "      <td>1.816667</td>\n",
              "      <td>1.840000</td>\n",
              "      <td>6.646200e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.850000</th>\n",
              "      <td>1.825000</td>\n",
              "      <td>1.920000</td>\n",
              "      <td>1.790000</td>\n",
              "      <td>1.850000</td>\n",
              "      <td>1.173585e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.860000</th>\n",
              "      <td>1.837500</td>\n",
              "      <td>1.895000</td>\n",
              "      <td>1.812500</td>\n",
              "      <td>1.860000</td>\n",
              "      <td>1.143455e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.870000</th>\n",
              "      <td>1.930000</td>\n",
              "      <td>1.950000</td>\n",
              "      <td>1.855000</td>\n",
              "      <td>1.870000</td>\n",
              "      <td>1.634030e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.880000</th>\n",
              "      <td>1.880000</td>\n",
              "      <td>1.896667</td>\n",
              "      <td>1.846667</td>\n",
              "      <td>1.880000</td>\n",
              "      <td>1.345987e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.890000</th>\n",
              "      <td>1.885000</td>\n",
              "      <td>1.920000</td>\n",
              "      <td>1.860000</td>\n",
              "      <td>1.890000</td>\n",
              "      <td>5.379950e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.900000</th>\n",
              "      <td>1.882500</td>\n",
              "      <td>1.950000</td>\n",
              "      <td>1.855000</td>\n",
              "      <td>1.900000</td>\n",
              "      <td>1.109292e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.910000</th>\n",
              "      <td>1.930000</td>\n",
              "      <td>1.955000</td>\n",
              "      <td>1.865000</td>\n",
              "      <td>1.910000</td>\n",
              "      <td>9.303750e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.920000</th>\n",
              "      <td>1.885000</td>\n",
              "      <td>1.945000</td>\n",
              "      <td>1.875000</td>\n",
              "      <td>1.920000</td>\n",
              "      <td>1.273620e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.930000</th>\n",
              "      <td>1.946667</td>\n",
              "      <td>1.990000</td>\n",
              "      <td>1.876667</td>\n",
              "      <td>1.930000</td>\n",
              "      <td>1.905627e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.940000</th>\n",
              "      <td>2.000000</td>\n",
              "      <td>2.000000</td>\n",
              "      <td>1.890000</td>\n",
              "      <td>1.940000</td>\n",
              "      <td>2.154490e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.950000</th>\n",
              "      <td>1.973333</td>\n",
              "      <td>2.013333</td>\n",
              "      <td>1.913333</td>\n",
              "      <td>1.950000</td>\n",
              "      <td>1.257690e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1.960000</th>\n",
              "      <td>1.935000</td>\n",
              "      <td>2.008333</td>\n",
              "      <td>1.893333</td>\n",
              "      <td>1.960000</td>\n",
              "      <td>1.696712e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19.770000</th>\n",
              "      <td>19.120001</td>\n",
              "      <td>19.820000</td>\n",
              "      <td>18.730000</td>\n",
              "      <td>19.770000</td>\n",
              "      <td>6.061660e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19.980000</th>\n",
              "      <td>19.790001</td>\n",
              "      <td>20.080000</td>\n",
              "      <td>19.350000</td>\n",
              "      <td>19.980000</td>\n",
              "      <td>6.298320e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20.020000</th>\n",
              "      <td>19.969999</td>\n",
              "      <td>20.280001</td>\n",
              "      <td>19.629999</td>\n",
              "      <td>20.020000</td>\n",
              "      <td>8.919550e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20.400000</th>\n",
              "      <td>19.980000</td>\n",
              "      <td>20.420000</td>\n",
              "      <td>19.860001</td>\n",
              "      <td>20.400000</td>\n",
              "      <td>5.562900e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20.900000</th>\n",
              "      <td>20.280001</td>\n",
              "      <td>20.920000</td>\n",
              "      <td>20.209999</td>\n",
              "      <td>20.900000</td>\n",
              "      <td>6.200270e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22.290001</th>\n",
              "      <td>21.190001</td>\n",
              "      <td>22.320000</td>\n",
              "      <td>21.139999</td>\n",
              "      <td>22.290001</td>\n",
              "      <td>1.134441e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23.980000</th>\n",
              "      <td>22.910000</td>\n",
              "      <td>24.000000</td>\n",
              "      <td>22.670000</td>\n",
              "      <td>23.980000</td>\n",
              "      <td>1.643282e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24.889999</th>\n",
              "      <td>25.290001</td>\n",
              "      <td>25.670000</td>\n",
              "      <td>24.760000</td>\n",
              "      <td>24.889999</td>\n",
              "      <td>1.036073e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25.049999</th>\n",
              "      <td>25.510000</td>\n",
              "      <td>26.180000</td>\n",
              "      <td>24.040001</td>\n",
              "      <td>25.049999</td>\n",
              "      <td>2.157712e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25.170000</th>\n",
              "      <td>24.889999</td>\n",
              "      <td>25.240000</td>\n",
              "      <td>24.719999</td>\n",
              "      <td>25.170000</td>\n",
              "      <td>6.520640e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25.200001</th>\n",
              "      <td>24.360001</td>\n",
              "      <td>25.410000</td>\n",
              "      <td>24.010000</td>\n",
              "      <td>25.200001</td>\n",
              "      <td>1.432232e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25.260000</th>\n",
              "      <td>24.940001</td>\n",
              "      <td>27.299999</td>\n",
              "      <td>24.629999</td>\n",
              "      <td>25.260000</td>\n",
              "      <td>3.250584e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>27.379999</th>\n",
              "      <td>26.959999</td>\n",
              "      <td>28.270000</td>\n",
              "      <td>26.799999</td>\n",
              "      <td>27.379999</td>\n",
              "      <td>1.233487e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>27.840000</th>\n",
              "      <td>28.120001</td>\n",
              "      <td>28.580000</td>\n",
              "      <td>27.190001</td>\n",
              "      <td>27.840000</td>\n",
              "      <td>1.439429e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>28.059999</th>\n",
              "      <td>25.620001</td>\n",
              "      <td>28.110001</td>\n",
              "      <td>25.570000</td>\n",
              "      <td>28.059999</td>\n",
              "      <td>1.925413e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>28.510000</th>\n",
              "      <td>29.410000</td>\n",
              "      <td>29.940001</td>\n",
              "      <td>26.840000</td>\n",
              "      <td>28.510000</td>\n",
              "      <td>2.573490e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>29.889999</th>\n",
              "      <td>28.150000</td>\n",
              "      <td>29.930000</td>\n",
              "      <td>27.840000</td>\n",
              "      <td>29.889999</td>\n",
              "      <td>1.622538e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>30.100000</th>\n",
              "      <td>30.020000</td>\n",
              "      <td>30.590000</td>\n",
              "      <td>29.370001</td>\n",
              "      <td>30.100000</td>\n",
              "      <td>1.599025e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>30.480000</th>\n",
              "      <td>33.160000</td>\n",
              "      <td>34.139999</td>\n",
              "      <td>29.870001</td>\n",
              "      <td>30.480000</td>\n",
              "      <td>3.041471e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>31.020000</th>\n",
              "      <td>31.190001</td>\n",
              "      <td>32.419998</td>\n",
              "      <td>30.910000</td>\n",
              "      <td>31.020000</td>\n",
              "      <td>1.297929e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>31.180000</th>\n",
              "      <td>32.099998</td>\n",
              "      <td>32.200001</td>\n",
              "      <td>30.639999</td>\n",
              "      <td>31.180000</td>\n",
              "      <td>1.231165e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>31.209999</th>\n",
              "      <td>31.520000</td>\n",
              "      <td>31.830000</td>\n",
              "      <td>30.510000</td>\n",
              "      <td>31.209999</td>\n",
              "      <td>1.242870e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>31.930000</th>\n",
              "      <td>32.990002</td>\n",
              "      <td>33.369999</td>\n",
              "      <td>31.200001</td>\n",
              "      <td>31.930000</td>\n",
              "      <td>1.766732e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32.189999</th>\n",
              "      <td>32.400002</td>\n",
              "      <td>32.599998</td>\n",
              "      <td>31.719999</td>\n",
              "      <td>32.189999</td>\n",
              "      <td>7.934730e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32.209999</th>\n",
              "      <td>29.910000</td>\n",
              "      <td>32.290001</td>\n",
              "      <td>29.450001</td>\n",
              "      <td>32.209999</td>\n",
              "      <td>1.978896e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32.430000</th>\n",
              "      <td>31.750000</td>\n",
              "      <td>33.230000</td>\n",
              "      <td>31.600000</td>\n",
              "      <td>32.430000</td>\n",
              "      <td>1.804106e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32.570000</th>\n",
              "      <td>33.180000</td>\n",
              "      <td>33.599998</td>\n",
              "      <td>32.189999</td>\n",
              "      <td>32.570000</td>\n",
              "      <td>1.185702e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32.590000</th>\n",
              "      <td>31.860001</td>\n",
              "      <td>32.630001</td>\n",
              "      <td>31.389999</td>\n",
              "      <td>32.590000</td>\n",
              "      <td>8.793440e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32.610001</th>\n",
              "      <td>31.129999</td>\n",
              "      <td>32.650002</td>\n",
              "      <td>30.910000</td>\n",
              "      <td>32.610001</td>\n",
              "      <td>1.183326e+08</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32.720001</th>\n",
              "      <td>31.430000</td>\n",
              "      <td>33.090000</td>\n",
              "      <td>30.540001</td>\n",
              "      <td>32.720001</td>\n",
              "      <td>2.177628e+08</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>987 rows × 5 columns</p>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 4,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df['Adj Close'].hist()\n",
        "plt.title('Histogram of Adj Close')\n",
        "plt.xlabel('Adj Close')\n",
        "plt.ylabel('Frequency')"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 5,
          "data": {
            "text/plain": [
              "Text(0,0.5,'Frequency')"
            ]
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ],
            "image/png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KqcRzq4Pp7wMuj4ifUY7lvDMzByiBswklmO6qfp6DNEFcNVgaRxFxDfCdzPx8u2uRJpIjE2mcRMT3gZnAgnbXIk00RyaSpNocmUiSajNMJEm1GSaSpNoME0lSbYaJJKk2w0SSVNv/B8inI4/guGb/AAAAAElFTkSuQmCC\n"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 5,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df = df.drop(['Date'], axis=1)"
      ],
      "outputs": [],
      "execution_count": 6,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "X = df.loc[:, df.columns != 'Adj Close']\n",
        "y = np.where (df['Adj Close'].shift(-1) > df['Adj Close'],1,-1)\n",
        "\n",
        "split = int(0.7*len(df))\n",
        "\nX_train, X_test, y_train, y_test = X[:split], X[split:], y[:split], y[split:]"
      ],
      "outputs": [],
      "execution_count": 7,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "model = LogisticRegression()\n",
        "model = model.fit(X_train,y_train)"
      ],
      "outputs": [],
      "execution_count": 8,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "pd.DataFrame(list(zip(X.columns, np.transpose(model.coef_))))"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 9,
          "data": {
            "text/plain": [
              "        0                     1\n",
              "0    Open  [-1.16225384009e-15]\n",
              "1    High   [-1.1725923238e-15]\n",
              "2     Low  [-1.15026223986e-15]\n",
              "3   Close  [-1.16249007296e-15]\n",
              "4  Volume  [-3.05621989828e-09]"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>0</th>\n",
              "      <th>1</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Open</td>\n",
              "      <td>[-1.16225384009e-15]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>High</td>\n",
              "      <td>[-1.1725923238e-15]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Low</td>\n",
              "      <td>[-1.15026223986e-15]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Close</td>\n",
              "      <td>[-1.16249007296e-15]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Volume</td>\n",
              "      <td>[-3.05621989828e-09]</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 9,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "probability = model.predict_proba(X_test)\n",
        "\nprint(probability)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 0.51051964  0.48948036]\n",
            " [ 0.50826892  0.49173108]\n",
            " [ 0.5059472   0.4940528 ]\n",
            " ..., \n",
            " [ 0.58961562  0.41038438]\n",
            " [ 0.56033033  0.43966967]\n",
            " [ 0.56678524  0.43321476]]\n"
          ]
        }
      ],
      "execution_count": 10,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "predicted = model.predict(X_test)"
      ],
      "outputs": [],
      "execution_count": 11,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(metrics.confusion_matrix(y_test, predicted))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[308   0]\n",
            " [352   0]]\n"
          ]
        }
      ],
      "execution_count": 12,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(metrics.classification_report(y_test, predicted))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "              precision    recall  f1-score   support\n",
            "\n",
            "          -1       0.47      1.00      0.64       308\n",
            "           1       0.00      0.00      0.00       352\n",
            "\n",
            "   micro avg       0.47      0.47      0.47       660\n",
            "   macro avg       0.23      0.50      0.32       660\n",
            "weighted avg       0.22      0.47      0.30       660\n",
            "\n"
          ]
        }
      ],
      "execution_count": 13,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(model.score(X_test,y_test))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "0.466666666667\n"
          ]
        }
      ],
      "execution_count": 14,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "cross_val = cross_val_score(LogisticRegression(), X, y, scoring='accuracy', cv=10)\n",
        "print(cross_val)\n",
        "print(cross_val.mean())"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[ 0.48868778  0.51131222  0.50909091  0.50909091  0.49090909  0.50909091\n",
            "  0.50909091  0.50909091  0.48858447  0.48858447]\n",
            "0.501353258614\n"
          ]
        }
      ],
      "execution_count": 15,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn.feature_selection import RFE\n",
        "\n",
        "# X = np.array(df[['Open', 'High', 'Low', 'Volume']].values)\n",
        "# y = np.array(df['Adj Close'].values)\n",
        "\n",
        "logreg = LogisticRegression()\n",
        "rfe = RFE(logreg, 20)\n",
        "rfe = rfe.fit(X, y)\n",
        "print(rfe.support_)\n",
        "print(rfe.ranking_)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[ True  True  True  True  True]\n",
            "[1 1 1 1 1]\n"
          ]
        }
      ],
      "execution_count": 16,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Different Method of Logistic Regression"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "stock_name = 'AMD'\n",
        "start = '2010-01-01' \n",
        "end = '2018-09-27'\n",
        "df = yf.download(stock_name, start, end)\n",
        "df = df.reset_index()\n",
        "df.head()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 downloaded\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 17,
          "data": {
            "text/plain": [
              "        Date  Open  High   Low  Close  Adj Close    Volume\n",
              "0 2010-01-04  9.79  9.90  9.68   9.70       9.70  18748700\n",
              "1 2010-01-05  9.71  9.90  9.68   9.71       9.71  22145700\n",
              "2 2010-01-06  9.68  9.76  9.55   9.57       9.57  18643400\n",
              "3 2010-01-07  9.51  9.55  9.18   9.47       9.47  26806800\n",
              "4 2010-01-08  9.37  9.47  9.29   9.43       9.43  13752800"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Date</th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2010-01-04</td>\n",
              "      <td>9.79</td>\n",
              "      <td>9.90</td>\n",
              "      <td>9.68</td>\n",
              "      <td>9.70</td>\n",
              "      <td>9.70</td>\n",
              "      <td>18748700</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2010-01-05</td>\n",
              "      <td>9.71</td>\n",
              "      <td>9.90</td>\n",
              "      <td>9.68</td>\n",
              "      <td>9.71</td>\n",
              "      <td>9.71</td>\n",
              "      <td>22145700</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2010-01-06</td>\n",
              "      <td>9.68</td>\n",
              "      <td>9.76</td>\n",
              "      <td>9.55</td>\n",
              "      <td>9.57</td>\n",
              "      <td>9.57</td>\n",
              "      <td>18643400</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>2010-01-07</td>\n",
              "      <td>9.51</td>\n",
              "      <td>9.55</td>\n",
              "      <td>9.18</td>\n",
              "      <td>9.47</td>\n",
              "      <td>9.47</td>\n",
              "      <td>26806800</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>2010-01-08</td>\n",
              "      <td>9.37</td>\n",
              "      <td>9.47</td>\n",
              "      <td>9.29</td>\n",
              "      <td>9.43</td>\n",
              "      <td>9.43</td>\n",
              "      <td>13752800</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 17,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df = df.drop(['Date'], axis=1)"
      ],
      "outputs": [],
      "execution_count": 18,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#X = df[['Open', 'High', 'Low', 'Volume']].values\n",
        "#y = df['Adj Close'].values\n",
        "X = df.loc[:, df.columns != 'Adj Close']\n",
        "y = np.where (df['Adj Close'].shift(-1) > df['Adj Close'],1,-1)\n",
        "\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)"
      ],
      "outputs": [],
      "execution_count": 19,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "model = LogisticRegression()\n",
        "model = model.fit (X_train,y_train)"
      ],
      "outputs": [],
      "execution_count": 20,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "pd.DataFrame(list(zip(X.columns, np.transpose(model.coef_))))"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 21,
          "data": {
            "text/plain": [
              "        0                    1\n",
              "0    Open  [8.15298772072e-17]\n",
              "1    High  [8.34788176473e-17]\n",
              "2     Low  [7.87561154695e-17]\n",
              "3   Close  [7.91884692417e-17]\n",
              "4  Volume  [1.55636449209e-11]"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>0</th>\n",
              "      <th>1</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Open</td>\n",
              "      <td>[8.15298772072e-17]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>High</td>\n",
              "      <td>[8.34788176473e-17]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Low</td>\n",
              "      <td>[7.87561154695e-17]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Close</td>\n",
              "      <td>[7.91884692417e-17]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Volume</td>\n",
              "      <td>[1.55636449209e-11]</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 21,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "probability = model.predict_proba(X_test)\n",
        "\nprint(probability)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 0.49997258  0.50002742]\n",
            " [ 0.49996825  0.50003175]\n",
            " [ 0.4999585   0.5000415 ]\n",
            " ..., \n",
            " [ 0.49994353  0.50005647]\n",
            " [ 0.49970723  0.50029277]\n",
            " [ 0.49989784  0.50010216]]\n"
          ]
        }
      ],
      "execution_count": 22,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "predicted = model.predict(X_test)"
      ],
      "outputs": [],
      "execution_count": 23,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(metrics.confusion_matrix(y_test, predicted))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[  0 352]\n",
            " [  0 308]]\n"
          ]
        }
      ],
      "execution_count": 24,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(metrics.classification_report(y_test, predicted))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "              precision    recall  f1-score   support\n",
            "\n",
            "          -1       0.00      0.00      0.00       352\n",
            "           1       0.47      1.00      0.64       308\n",
            "\n",
            "   micro avg       0.47      0.47      0.47       660\n",
            "   macro avg       0.23      0.50      0.32       660\n",
            "weighted avg       0.22      0.47      0.30       660\n",
            "\n"
          ]
        }
      ],
      "execution_count": 25,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(model.score(X_test,y_test))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "0.466666666667\n"
          ]
        }
      ],
      "execution_count": 26,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "cross_val = cross_val_score(LogisticRegression(), X, y, scoring='accuracy', cv=10)\n",
        "print(cross_val)\n",
        "print(cross_val.mean())"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[ 0.48868778  0.51131222  0.50909091  0.50909091  0.49090909  0.50909091\n",
            "  0.50909091  0.50909091  0.48858447  0.48858447]\n",
            "0.501353258614\n"
          ]
        }
      ],
      "execution_count": 27,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "logreg = LogisticRegression()\n",
        "rfe = RFE(logreg, 20)\n",
        "rfe = rfe.fit(X, y)\n",
        "print(rfe.support_)\n",
        "print(rfe.ranking_)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[ True  True  True  True  True]\n",
            "[1 1 1 1 1]\n"
          ]
        }
      ],
      "execution_count": 28,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Different Method of Logistic Regression"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "stock_name = 'AMD'\n",
        "start = '2010-01-01' \n",
        "end = '2018-09-27'\n",
        "df = yf.download(stock_name, start, end)\n",
        "df = df.reset_index()\n",
        "df.head()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 downloaded\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 29,
          "data": {
            "text/plain": [
              "        Date  Open  High   Low  Close  Adj Close    Volume\n",
              "0 2010-01-04  9.79  9.90  9.68   9.70       9.70  18748700\n",
              "1 2010-01-05  9.71  9.90  9.68   9.71       9.71  22145700\n",
              "2 2010-01-06  9.68  9.76  9.55   9.57       9.57  18643400\n",
              "3 2010-01-07  9.51  9.55  9.18   9.47       9.47  26806800\n",
              "4 2010-01-08  9.37  9.47  9.29   9.43       9.43  13752800"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Date</th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2010-01-04</td>\n",
              "      <td>9.79</td>\n",
              "      <td>9.90</td>\n",
              "      <td>9.68</td>\n",
              "      <td>9.70</td>\n",
              "      <td>9.70</td>\n",
              "      <td>18748700</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2010-01-05</td>\n",
              "      <td>9.71</td>\n",
              "      <td>9.90</td>\n",
              "      <td>9.68</td>\n",
              "      <td>9.71</td>\n",
              "      <td>9.71</td>\n",
              "      <td>22145700</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2010-01-06</td>\n",
              "      <td>9.68</td>\n",
              "      <td>9.76</td>\n",
              "      <td>9.55</td>\n",
              "      <td>9.57</td>\n",
              "      <td>9.57</td>\n",
              "      <td>18643400</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>2010-01-07</td>\n",
              "      <td>9.51</td>\n",
              "      <td>9.55</td>\n",
              "      <td>9.18</td>\n",
              "      <td>9.47</td>\n",
              "      <td>9.47</td>\n",
              "      <td>26806800</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>2010-01-08</td>\n",
              "      <td>9.37</td>\n",
              "      <td>9.47</td>\n",
              "      <td>9.29</td>\n",
              "      <td>9.43</td>\n",
              "      <td>9.43</td>\n",
              "      <td>13752800</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 29,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.describe()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 30,
          "data": {
            "text/plain": [
              "              Open         High          Low        Close    Adj Close  \\\n",
              "count  2200.000000  2200.000000  2200.000000  2200.000000  2200.000000   \n",
              "mean      6.725291     6.862077     6.584586     6.724877     6.724877   \n",
              "std       4.546764     4.658969     4.440715     4.560555     4.560555   \n",
              "min       1.620000     1.690000     1.610000     1.620000     1.620000   \n",
              "25%       3.340000     3.397500     3.290000     3.330000     3.330000   \n",
              "50%       5.755000     5.870000     5.675000     5.760000     5.760000   \n",
              "75%       8.772500     8.950000     8.615000     8.800000     8.800000   \n",
              "max      33.180000    34.139999    32.189999    32.720001    32.720001   \n",
              "\n",
              "             Volume  \n",
              "count  2.200000e+03  \n",
              "mean   3.242892e+07  \n",
              "std    3.115767e+07  \n",
              "min    0.000000e+00  \n",
              "25%    1.395668e+07  \n",
              "50%    2.238215e+07  \n",
              "75%    3.880502e+07  \n",
              "max    3.250584e+08  "
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>count</th>\n",
              "      <td>2200.000000</td>\n",
              "      <td>2200.000000</td>\n",
              "      <td>2200.000000</td>\n",
              "      <td>2200.000000</td>\n",
              "      <td>2200.000000</td>\n",
              "      <td>2.200000e+03</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mean</th>\n",
              "      <td>6.725291</td>\n",
              "      <td>6.862077</td>\n",
              "      <td>6.584586</td>\n",
              "      <td>6.724877</td>\n",
              "      <td>6.724877</td>\n",
              "      <td>3.242892e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>std</th>\n",
              "      <td>4.546764</td>\n",
              "      <td>4.658969</td>\n",
              "      <td>4.440715</td>\n",
              "      <td>4.560555</td>\n",
              "      <td>4.560555</td>\n",
              "      <td>3.115767e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>min</th>\n",
              "      <td>1.620000</td>\n",
              "      <td>1.690000</td>\n",
              "      <td>1.610000</td>\n",
              "      <td>1.620000</td>\n",
              "      <td>1.620000</td>\n",
              "      <td>0.000000e+00</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25%</th>\n",
              "      <td>3.340000</td>\n",
              "      <td>3.397500</td>\n",
              "      <td>3.290000</td>\n",
              "      <td>3.330000</td>\n",
              "      <td>3.330000</td>\n",
              "      <td>1.395668e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>50%</th>\n",
              "      <td>5.755000</td>\n",
              "      <td>5.870000</td>\n",
              "      <td>5.675000</td>\n",
              "      <td>5.760000</td>\n",
              "      <td>5.760000</td>\n",
              "      <td>2.238215e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>75%</th>\n",
              "      <td>8.772500</td>\n",
              "      <td>8.950000</td>\n",
              "      <td>8.615000</td>\n",
              "      <td>8.800000</td>\n",
              "      <td>8.800000</td>\n",
              "      <td>3.880502e+07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>max</th>\n",
              "      <td>33.180000</td>\n",
              "      <td>34.139999</td>\n",
              "      <td>32.189999</td>\n",
              "      <td>32.720001</td>\n",
              "      <td>32.720001</td>\n",
              "      <td>3.250584e+08</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 30,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "X = df.ix[:,(1,2,3,6)].values\n",
        "y = np.where (df['Adj Close'].shift(-1) > df['Adj Close'],1,-1)"
      ],
      "outputs": [],
      "execution_count": 31,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .3, random_state=25)"
      ],
      "outputs": [],
      "execution_count": 32,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "LogReg = LogisticRegression()\n",
        "LogReg.fit(X_train, y_train)"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 33,
          "data": {
            "text/plain": [
              "LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n",
              "          intercept_scaling=1, max_iter=100, multi_class='warn',\n",
              "          n_jobs=None, penalty='l2', random_state=None, solver='warn',\n",
              "          tol=0.0001, verbose=0, warm_start=False)"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 33,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "y_pred = LogReg.predict(X_test)"
      ],
      "outputs": [],
      "execution_count": 34,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn.metrics import confusion_matrix\n",
        "confusion_matrix = confusion_matrix(y_test, y_pred)\n",
        "confusion_matrix"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 35,
          "data": {
            "text/plain": [
              "array([[  0, 345],\n",
              "       [  0, 315]], dtype=int64)"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 35,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(metrics.classification_report(y_test, y_pred))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "              precision    recall  f1-score   support\n",
            "\n",
            "          -1       0.00      0.00      0.00       345\n",
            "           1       0.48      1.00      0.65       315\n",
            "\n",
            "   micro avg       0.48      0.48      0.48       660\n",
            "   macro avg       0.24      0.50      0.32       660\n",
            "weighted avg       0.23      0.48      0.31       660\n",
            "\n"
          ]
        }
      ],
      "execution_count": 36,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(LogReg.predict(X_test))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
            " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n"
          ]
        }
      ],
      "execution_count": 37,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "X_test"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 38,
          "data": {
            "text/plain": [
              "array([[  4.01000000e+00,   4.02000000e+00,   3.95000000e+00,\n",
              "          1.12703000e+07],\n",
              "       [  1.20300000e+01,   1.20400000e+01,   1.15800000e+01,\n",
              "          8.96744000e+07],\n",
              "       [  6.82000000e+00,   7.08000000e+00,   6.79000000e+00,\n",
              "          2.89094000e+07],\n",
              "       ..., \n",
              "       [  1.27600000e+01,   1.28900000e+01,   1.25400000e+01,\n",
              "          5.88615000e+07],\n",
              "       [  7.24000000e+00,   7.50000000e+00,   7.22000000e+00,\n",
              "          2.12470000e+07],\n",
              "       [  8.36000000e+00,   8.43000000e+00,   8.10000000e+00,\n",
              "          2.29465000e+07]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 38,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "score = LogReg.score(X_test, y_test)\n",
        "print(score)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "0.477272727273\n"
          ]
        }
      ],
      "execution_count": 39,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "cross_val = cross_val_score(LogisticRegression(), X, y, scoring='accuracy', cv=10)\n",
        "print(cross_val)\n",
        "print(cross_val.mean())"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[ 0.48868778  0.51131222  0.50909091  0.50909091  0.49090909  0.50909091\n",
            "  0.50909091  0.50909091  0.48858447  0.48858447]\n",
            "0.501353258614\n"
          ]
        }
      ],
      "execution_count": 40,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    }
  ],
  "metadata": {
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "version": "3.5.5",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "mimetype": "text/x-python",
      "name": "python",
      "file_extension": ".py"
    },
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    },
    "nteract": {
      "version": "0.12.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}